// Copyright (C) 2022 Linlexiao
#ifndef RESULT_H
#define RESULT_H

#include <QList>
#include <QString>
#include <QVector>

#include "pai.h"
#include "yaku.h"

enum PointType { OYATSUMO = 0b00, OYARON = 0b01, KOTSUMO = 0b10, KORON = 0b11 };
enum ManType { NOMANGAN, MANGAN, HANEMAN, BAIMAN, SANBAIMAN, KAZOEYUAKUMAN };

// 计算结果类
class Result {
 private:
    static const char sep1 = '%';
    static const char sep2 = '^';

 public:
    Result();
    int han, fu;
    int point1, point2;
    PointType pointType;
    ManType manType;
    QVector<QString> yaku;
    bool isYakuman;
};

// 计算器 TODO 把它变成单例模式?
class Calculator {
 private:
    void _calculateYaku(HandSet hand, Result& result);
    void _calculateFu(HandSet hand, Result& result);
    void _calculatePoint(Result& x);

    void _calculateKokushi();
    void _calculateChiitui();
    //回溯搜索，结果保存在nowHandSet中
    void _calculateNormal(int dep);

    HandSet nowHandSet;
    QVector<Pai> nowP;  // TODO 性能优化 链表
    Result result;
    QVector<Yaku*> yakus;
    QVector<Yaku*> yakumanYakus;

    int pow2[20]{};

 public:
    Calculator();
    Result calculate(const State& state);
};

#endif  // RESULT_H
